package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.bo.UserInfo;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Classname BusinessModelInternetAttrHandler
 * @Description 互联网专线-业务模式，不同省，枚举值不同
 * @Author zhangsong
 * @Date 2022-03-29 17:40
 */
public class BusinessModelInternetAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        String provinceCode = null;
        UserInfo userInfo = ContextUtil.getLoginInfo().getUserInfo();
        if (userInfo != null) {
            provinceCode = userInfo.getPostProvinceNbr();
        }

        List<KiteAttrValue> attrValues = attr.getAttrValues();
        if(KiteListUtils.isNotEmpty(attrValues)) {
            KiteSceneInst kiteSceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
            String offerId = querySceneInstService.getOfferInst(kiteSceneInst.getCustId(), kiteSceneInst.getRootInstId()).getOfferId();

            if("50040853".equals(offerId)) {
                // 国际互联网，业务模式枚举值：1_0000110-OutBound业务
                attrValues = attrValues.stream().filter(attrValue -> KiteStringUtils.isEqual(attrValue.getAttrValue(), "1_0000110")).collect(Collectors.toList());
            } /*else if(KiteStringUtils.isEqual(provinceCode, LocalKeyConsts.PROVINCE_SHANGHAI)) {
                // 上海，业务模式枚举值：1_0000108-国内业务、1_0000110-OutBound业务
                attrValues = attrValues.stream().filter(attrValue -> KiteStringUtils.equalsAny(attrValue.getAttrValue(), "1_0000108","1_0000110")).collect(Collectors.toList());
            }*/ else {
                // 其他，业务模式枚举值：1_0000108-国内业务
                attrValues = attrValues.stream().filter(attrValue -> KiteStringUtils.isEqual(attrValue.getAttrValue(), "1_0000108")).collect(Collectors.toList());
            }
            attr.setAttrValues(attrValues);
        }

        super.after(attr, inst, data);
    }
}
